﻿using Super_Management_Mayhem.Content.Animations;
using Super_Management_Mayhem.Content.Spritesheet;
using Transformable_Engine_v2.Engine.Animation.ColorAnimation;
using Transformable_Engine_v2.Engine.Animation.FrameAnimation;
using Transformable_Engine_v2.Engine.Animation.PositionAnimation;
using Transformable_Engine_v2.Engine.Animation.Trajectory;
using Transformable_Engine_v2.Engine.GameObjects.Containers;
using Transformable_Engine_v2.Engine.Graphics;
using Transformable_Engine_v2.Engine.Helper;
using Transformable_Engine_v2.Engine.Time;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Super_Management_Mayhem.Screens.Menu.SelectAvatar
{
    public class NewIcon : Container
    {
        private Container _icon;
         public NewIcon()
         {
             _icon = new ImageContainer {
                                            Sprite = MenuSheet.GetSprite(MenuSheet.NewIcon.Icon),
                                            Origin = TE_Rectangle.Alignment.CenterMiddle,
                                            Scale = new TE_Vector2(2, 2),
                                        };                      
            _icon.AddAnimations(new PositionAnimation(new SinusTrajectory(), new TE_Vector2(0, -1), 1200, true, 0));
            AddChildren(_icon);

            Timer starTimer = new Timer(150, true, CreateStar);
             starTimer.Start();
             AddTimers(starTimer);
         }

        private void CreateStar()
        {
            TE_Vector2 position = _icon.Position + new TE_Vector2((float) Randomizer.Double(-2.5, 2.5), (float) Randomizer.Double(-1, 1)).ToGridbound();

            var star = new ImageContainer {
                                              Position = position,
                                              Sprite = MenuSheet.GetSprite(MenuSheet.NewIcon.Star0),
                                              Origin = TE_Rectangle.Alignment.CenterMiddle,
                                              Scale = new TE_Vector2(2, 2)
                                          };
            star.AddAnimations(new FrameAnimation(new NewStar()));
            star.AddAnimations(new PositionUniformLinearAnimation(0, new TE_Vector2(0, -1)));
            star.AddAnimations(new ColorAnimation(new LinearEasing(), Color.Transparent, 2000, false, 0));
            star.Die(2000);

            AddChildren(star);
        }
    }
}